package com.joysuch.wwyt.mh.controller;

import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.support.Context;
import com.joysuch.wwyt.mh.bean.MhAlarmLevelConfigBean;
import com.joysuch.wwyt.mh.bean.MhAlarmLimitConfigBean;
import com.joysuch.wwyt.mh.entity.MhAlarmLevelConfig;
import com.joysuch.wwyt.mh.entity.MhAlarmLimitConfig;
import com.joysuch.wwyt.mh.service.MhAlarmLevelConfigService;
import com.joysuch.wwyt.mh.service.MhAlarmLimitConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Leong
 * @date 2022/9/21 14:55
 */
@RestController
@Api(tags = "监测点-报警参数设置")
@RequestMapping("/mh/alarm-config")
public class MhAlarmConfigController {

    @Resource
    private MhAlarmLevelConfigService alarmLevelConfigService;

    @Resource
    private MhAlarmLimitConfigService alarmLimitConfigService;

    @GetMapping("/level/list")
    @ApiOperation(value = "报警等级列表")
    public ResultBean list() {
        List<MhAlarmLevelConfig> list = alarmLevelConfigService.findList(Context.getCurrentTenantId(),Context.getCompanyCode());
        return ResultBean.wrapSuccessfulResult(list);
    }

    @PostMapping("/update/level")
    @ApiOperation(value = "修改报警等级")
    public ResultBean updateLevel(@Validated @RequestBody List<MhAlarmLevelConfigBean> beans) {
        alarmLevelConfigService.updateLevel(beans);
        return ResultBean.success(null);
    }

    @GetMapping("/limit/list")
    @ApiOperation(value = "报警触发配置")
    public ResultBean limit() {
        MhAlarmLimitConfig config = alarmLimitConfigService.findOneConfig(Context.getCurrentTenantId(),Context.getCompanyCode());
        return ResultBean.wrapSuccessfulResult(config);
    }

    @PostMapping("/update/limit")
    @ApiOperation(value = "修改报警触发配置")
    public ResultBean limit(@Validated @RequestBody MhAlarmLimitConfigBean bean) {
        alarmLimitConfigService.updateLimit(bean);
        return ResultBean.success(null);
    }
}
